#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <limits.h>
#include <math.h>
using namespace std;

void get_div_num(vector<int>& a, int n)
{
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            a.push_back(i);
            if (n / i != i) a.push_back(n / i);
        }
    }
}

int jump(int n, int m)
{
    vector<int> step(m + 1, INT_MAX);
    step[n] = 0;
    for (int i = n; i < m; i++) {
        if (step[i] == INT_MAX) continue;
        vector<int> a;
        get_div_num(a, i);
        for (int j = 0; j < a.size(); j++) {
            if (a[j] + i <= m && step[a[j] + i] != INT_MAX) {
                step[a[j] + i] =
                    step[a[j] + i] < step[i] + 1 ? step[a[j] + i] : step[i] + 1;
            }
            else if (a[j] + i <= m) {
                step[a[j] + i] = step[i] + 1;
            }
        }
        a.clear();
    }
    return step[m] == INT_MAX ? -1 : step[m];
}

int main()
{
    int n, m;
    int count = 0;
    while (cin >> n >> m) {
        count = jump(n, m);
        cout << count << endl;
    }
    return 0;
}
